using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class healthCollect : MonoBehaviour
{
    private int n;
    //设置一个参数检查碰撞次数
    public int amount;
    //草莓加血量
    private void OnTriggerEnter2D(Collider2D other) //每检测到一次碰撞，就运行一次该函数
    {
        n = n + 1;
        Debug.Log($"{other}+1,这是第{n}次碰撞！");
        RubyController rubyController = other.GetComponent<RubyController>();
        //获取ruby游戏对象的脚本组件对象
        if(rubyController != null)
        {
            if(rubyController.health != rubyController.maxhealth)
            {
                rubyController.changeHealth(amount);
                //调用rubycontroller中的changehealth方法
                Destroy(gameObject);
                //在碰撞发生后销毁该组件的对象，即销毁草莓
            }
            else
            {
                Debug.Log("满血无需加血");
            }
        }
        else
        {
            Debug.Log("未获取游戏对象");
        }
    }
}
